﻿using Sage.DownloadLite.Utils;

namespace Sage.DownloadLite.Models
{
    /// <summary>
    /// 批量下载结果
    /// </summary>
    public class BatchDownloadResult
    {
        /// <summary>
        /// 是否全部成功
        /// </summary>
        public bool Success { get; set; }
        /// <summary>
        /// 已完成的任务结果（包含成功和失败）
        /// </summary>
        public List<TaskResult> CompletedTasks { get; set; } = [];
        /// <summary>
        /// 被取消的任务结果
        /// </summary>
        public List<TaskResult> CancelledTasks { get; set; } = [];
        /// <summary>
        /// 错误消息
        /// </summary>
        public string? ErrorMessage { get; set; }
        /// <summary>
        /// 总耗时
        /// </summary>
        public TimeSpan TotalTime { get; set; }
        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime StartTime { get; set; }
        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime EndTime { get; set; }
        /// <summary>
        /// 总任务数
        /// </summary>
        public int TotalTasks => CompletedTasks.Count + CancelledTasks.Count;
        /// <summary>
        /// 成功任务数
        /// </summary>
        public int SuccessfulTasks => CompletedTasks.Count(t => t.Success);
        /// <summary>
        /// 失败任务数
        /// </summary>
        public int FailedTasks => CompletedTasks.Count(t => !t.Success);
        /// <summary>
        /// 取消任务数
        /// </summary>
        public int CancelledTasksCount => CancelledTasks.Count;
        /// <summary>
        /// 成功率百分比
        /// </summary>
        public double SuccessRate => TotalTasks > 0 ? (double)SuccessfulTasks / TotalTasks * 100 : 0;
        /// <summary>
        /// 总下载文件大小
        /// </summary>
        public long TotalDownloadedSize => CompletedTasks.Where(t => t.Success).Sum(t => t.FileSize);
        /// <summary>
        /// 格式化的总下载大小
        /// </summary>
        public string FormattedTotalSize => BytesFormatter.Format(TotalDownloadedSize);
    }
}